package com.flyou.consumer.controller;

import com.flyou.pojo.User;
import com.flyou.service.UserService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
@Log4j2
@RefreshScope
public class UserController {
    @Autowired
    UserService userService;

    @Value("${test.name}")
    private String userNmae;
    @GetMapping("/user/{id}")
    public User findUserById(@PathVariable(name = "id") Long id) {
        log.info(id);
        if (id==1){
            throw  new RuntimeException();
        }
        log.info("登录用户标识{}",userNmae);
        return userService.queryUserById(id);
    }
}
